<template>
    <div v-if="tkIsShow">
        <div class="zhezhao"></div>
        <div class="tankuang">
            <div class="tk_title">{{ title }}</div>
            <img src="../assets/icon-close.png" class="tk_close" @click="closeTk">
            <div class="tk_content">
                <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="名称" prop="sortName">
                        <el-input v-model="form.sortName"></el-input>
                    </el-form-item>
                    <el-form-item label="排序" prop="level">
                        <el-input type="number" v-model="form.level"></el-input>
                    </el-form-item>
                    <el-form-item label="是否显示" prop="isShow">
                        <el-radio-group v-model="form.isShow">
                            <el-radio :label="1">显示</el-radio>
                            <el-radio :label="0">隐藏</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>
<script>
import { UPLOAD_URL } from '@/utils/http.js';
export default {
  data() {
    return {
        UPLOAD_URL,
        tkIsShow:false,
        title:"",
        form:{},
        rules: {
            sortName: [
                {required: true,message: "请输入分类名称",trigger: ["blur,change"]}
            ],
            level: [
                {required: true,message: "请输入排序",trigger: ["blur,change"]}
            ],
            isShow: [
                {required: true,message: "请选择排序",trigger: ["blur,change"]}
            ],
        },
        fileList:[]
    };
  },
  methods: {
    __init(str, id,parentId,obj = null,type) {
        if (str == "add") {
            this.form={
                id:0,
                sortName:'',
                level:1,
                parentId:parentId,
                isShow:1,
                type:type,
                iconPic:''
            }
        }else{
            console.log(obj)
            this.form={
                id:id,
                sortName:obj.sortName,
                level:obj.level,
                parentId:parentId,
                isShow:obj.isShow,
                type:type,
                iconPic:''
            }
        }
    },
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            var url="manager/editTemplateImageByPage";
            var params={
                ...this.form
            }
            this.$post(url, params).then((res) => {
                console.log(res)
                if (res.code === 0) {
                    this.$message.success(res.msg)
                    this.closeTk();
                } else {
                    this.$message.error(res.msg)
                }
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
    },
    resetForm(formName) {
        this.$refs[formName].resetFields();
    },
    closeTk(){
        this.tkIsShow = false;
        this.$emit("close");
    },
    handleSuccess(response, file, fileList) {
        console.log(response);
        if(response.code==0){
            this.$message.success('上传成功');
            this.form.iconPic=response.data;
        }
    }
  }
}
</script>
<style scoped lang="scss">
  .zhezhao{
    position: fixed;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.2;
    top: 0;
    left: 0;
    z-index: 200;
  }
  .tankuang{
    position: fixed;
    width: 30%;
    background-color: #fff;
    top: 15%;
    left: 35%;
    z-index: 201;
    border-radius: 5px;
  }
  .tk_title{
    font-size: 17px;
    margin: 15px 0;
  }
  .tk_content{
    width: 80%;
    margin-left: 10%;
  }
  .tk_close{
    position: absolute;
    width: 16px;
    height: 16px;
    top: 18px;
    right: 20px;
  }
</style>